package top.chengdongqing.mishop.utils

import jakarta.servlet.http.HttpServletRequest

/**
 * IP工具类
 */
object IpUtils {

    fun getClientIP(request: HttpServletRequest): String {
        var ipAddress = request.getHeader("X-Forwarded-For")

        if (ipAddress.isNullOrEmpty() || "unknown".equals(ipAddress, ignoreCase = true)) {
            ipAddress = request.getHeader("Proxy-Client-IP")
        }
        if (ipAddress.isNullOrEmpty() || "unknown".equals(ipAddress, ignoreCase = true)) {
            ipAddress = request.getHeader("WL-Proxy-Client-IP")
        }
        if (ipAddress.isNullOrEmpty() || "unknown".equals(ipAddress, ignoreCase = true)) {
            ipAddress = request.remoteAddr
        }

        return ipAddress
    }
}